home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / polynomial / deconv.m < prev    next >
Text File  |  1997-03-07  |  2KB  |  73 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: deconv (y, a)
  21. ##
  22. ## Deconvolve two vectors.
  23. ##
  24. ## [b, r] = deconv (y, a) solves for b and r such that
  25. ##    y = conv(a,b) + r
  26. ##
  27. ## If y and a are polynomial coefficient vectors, b will contain the
  28. ## coefficients of the polynomial quotient and r will be a remander
  29. ## polynomial of lowest order.
  30. ##
  31. ## SEE ALSO: conv, poly, roots, residue, polyval, polyderiv,
  32. ## polyinteg
  33.  
  34. ## Author: Tony Richardson <amr@mpl.ucsd.edu>
  35. ## Created: June 1994
  36. ## Adapted-By: jwe
  37.  
  38. function [b, r] = deconv (y, a)
  39.  
  40.   if (nargin != 2)
  41.     usage ("deconv (y, a)");
  42.   endif
  43.  
  44.   if (! (is_vector (y) && is_vector (a)))
  45.     error("conv: both arguments must be vectors");
  46.   endif
  47.  
  48.   la = length (a);
  49.   ly = length (y);
  50.  
  51.   lb = ly - la + 1;
  52.  
  53.   if (ly > la)
  54.     b = filter (y, a, [1, (zeros (1, ly - la))]);
  55.   elseif (ly == la)
  56.     b = filter (y, a, 1);
  57.   else
  58.     b = 0;
  59.   endif
  60.  
  61.   b = polyreduce (b);
  62.  
  63.   lc = la + length (b) - 1;
  64.   if (ly == lc)
  65.     r = y - conv (a, b);
  66.   else
  67.     r = [(zeros (1, lc - ly)), y] - conv (a, b);
  68.   endif
  69.  
  70.   r = polyreduce (r);
  71.  
  72. endfunction
  73.